<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script src="https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.js"></script>
  <script src="../../cdn/vue/vue.global.min.js"></script>
  <link rel="stylesheet" href="../../cdn/element-plus/index.css" />
  <script src="../../cdn/element-plus/index.full.min.js"></script>

  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <avue-form v-model="data" ref="form" :option="option" @submit="submit"></avue-form>
  </div>
</body>
<script>
  let baseUrl = 'https://cli.avuejs.com/api/area'
  let app = Vue.createApp({
    el: '#app',
    data() {
      return {
        data: {
          number: 1,
        },
        option: {
          props: {
            label: 'name',
            value: 'code'
          },
          column: [{
            prop: 'number',
            type: 'radio',
            dataType: 'number',
            props: {
              label: 'label',
              value: 'value'
            },
            dicData: [{
              label: "1",
              value: '1'
            }, {
              label: "2",
              value: '2'
            }, {
              label: "3",
              value: '3'
            }],
          },
          {
            label: '省份',
            prop: 'province',
            type: 'select',
            cascader: ['city'],
            dicUrl: `${baseUrl}/getProvince`,
            rules: [
              {
                required: true,
                message: '请选择省份',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '城市',
            prop: 'city',
            type: 'select',
            cascader: ['area'],
            dicFlag: false,
            hide: true,
            dicUrl: `${baseUrl}/getCity/{{key}}`,
            rules: [
              {
                required: true,
                message: '请选择城市',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '地区',
            prop: 'area',
            dicFlag: false,
            hide: true,
            type: 'select',
            dicUrl: `${baseUrl}/getArea/{{key}}`,
            rules: [
              {
                required: true,
                message: '请选择地区',
                trigger: 'blur'
              }
            ]
          }
          ]
        }
      }
    },
    mounted() {
      setTimeout(() => {
        this.setValue();
      }, 0);
    },
    methods: {
      submit() {
        this.$message.success('当前数据' + JSON.stringify(this.data))
      },
      setValue() {
        this.data.province = "210000";
        this.data.city = "210100";
        this.data.area = "210104";
      }
    }
  })
  app.use(ElementPlus)
  app.use(AVUE)
  app.mount('#app')
</script>

</html>